//
//  HERoomUserDetailsViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/3/4.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HERoomUserDetailsViewController.h"
#import "HEFillAccusationViewController.h"

@interface HERoomUserDetailsViewController ()<QMUITextViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
// 约束参照视图,也是容器视图
@property (nonatomic, strong) UIView *contentView;

@property (nonatomic, strong) UIImageView *userIcon;

@property (nonatomic, strong) UILabel *usernameLb;

@property (nonatomic, strong) QMUIGhostButton *selectBtn;
 

@end

@implementation HERoomUserDetailsViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"用户信息";
     
    [self initUI];
}

- (void)initUI {
    
    // 1. 添加scrollView
    [self.view addSubview:self.scrollView];
    // 2. 添加参照视图
    [self.scrollView addSubview:self.contentView];
    
    
    [self.contentView addSubview:self.userIcon];
    [self.contentView addSubview:self.usernameLb];
    
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:_user.avatarUrlString] placeholderImage:IMAGE_NAMED(@"defualt_icon")];

    self.usernameLb.text = _user.showName;
 
    
    [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(40);
        make.width.height.offset(80);
        make.centerX.equalTo(self.contentView);
    }];
    
    [self.usernameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userIcon.mas_bottom).offset(30);
        make.height.offset(20);
        make.centerX.equalTo(self.contentView);
    }];
    
    UserInfo *user = [UserManager sharedUserManager].curUserInfo;
    if (![user.id isEqualToString:_user.infoId]) {
        // 提交
        QMUIFillButton *submitBtn = [[QMUIFillButton alloc] initWithFillColor:CPriceColor titleTextColor:CNavBgFontColor];
        submitBtn.titleLabel.font = UIFontMake(16);
        [submitBtn setTitle:@"举报" forState:UIControlStateNormal];
        [_contentView addSubview:submitBtn];
        [submitBtn addTarget:self action:@selector(submitApply) forControlEvents:UIControlEventTouchUpInside];


        [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.left.equalTo(_contentView).mas_offset(40);
            make.right.equalTo(_contentView).mas_offset(-40);
            make.height.mas_offset(40);
            make.bottom.equalTo(_contentView).mas_offset(-50);
        }];
    }
}

- (void)submitApply {
    HEFillAccusationViewController *vc = [HEFillAccusationViewController new];
    vc.user = _user;
    vc.roomId = _roomId;
    [self.navigationController pushViewController:vc animated:YES];
}
 

#pragma mark -
- (UIImageView *)userIcon {
    if (!_userIcon) {
        _userIcon = [UIImageView new];
        _userIcon.layer.masksToBounds = YES;
        _userIcon.layer.cornerRadius = 40;
    }
    return _userIcon;
}

- (UILabel *)usernameLb {
    if (!_usernameLb) {
        _usernameLb = [UILabel new];
        _usernameLb.font = DYFont(16);
    }
    return _usernameLb;
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    // 布局子控件
    // 设置scrollView约束
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(ZXNavBarHeight, 0, 0, 0));
    }];
    
    // 设置参照视图的约束
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
//        make.height.greaterThanOrEqualTo(@0.0f);
        make.height.mas_greaterThanOrEqualTo(kScreenHeight-ZXNavBarHeight);
    }];
}

#pragma mark - getters
// scrollView
- (UIScrollView *)scrollView {
    if (_scrollView == nil) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.backgroundColor = KWhiteColor;
        _scrollView.alwaysBounceVertical = YES;
        _scrollView.bounces = YES;
    }
    return _scrollView;
}

// 约束参照视图
- (UIView *)contentView {
    if (_contentView == nil) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = KWhiteColor;
    }
    return _contentView;
}

@end
